package com.tth.learn.addproperties.java;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @Author tth
 * @Date 2022/11/18 15:10
 */
public class Test {
    public static void main(String[] args) {
        String s = "12345678910111213";
        char[] chars = s.toCharArray();

        System.out.println(chars[12]);
    }

    private static void cyclicBarrierTest() {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(7, () -> {
            System.out.println("召唤神龙成功");
        });

        for (int i = 1; i <= 7; i++) {
            final int temp = i;
            new Thread(()-> {
                System.out.println(Thread.currentThread().getName()+"收集了"+temp+"个龙珠");

                try {
                    cyclicBarrier.await();//等待
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }

}
